function ajaxFileUpload(id, url, fileEleId)
{
	var loading = $("body").busyBox({
        spinner: '<img src="/images/admin/ajax-loader.gif" />'
    });
    
	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	$.ajaxFileUpload
	(
		{
			url:url,
			secureuri:false,
			//fileElementId:'fileToUpload',
			fileElementId: fileEleId,
			//dataType: 'json',
			type: "POST",
			data:{page_id: id},
			//data:{name:'logan', id:'id'},
			success: function (data, status)
			{
				//window.location.reload();
			},
			complete: function complete(XMLHttpRequest, textStatus){
            	loading.busyBox('close');
        	},
			error: function (data, status, e)
			{
				alert(e);
			}
			
		}
	)
	
	//return false;

}

function deleteUser(userid)
{
	var msg = confirm ("Are you sure you want to delete this user?")
	if (msg) {
    	//location.href = '/admin/user/deleteuser/userid/'+userid;
    	user_arr = userid + "--";
    	$.ajax({
    		type: "POST",
    		data: ({user_arr: userid}),
        	url: "/admin/user/deleteuser/",
        	success: function(data, textStatus, XMLHttpRequest){
        	   alert(data);      
        	},
        	complete: function complete(XMLHttpRequest, textStatus){
                loading.busyBox('close');
            }
    	});
	} else {
	   return false;
	} 
}

function del(id, path)
{
	var msg = confirm ("Are you sure you want to delete this record?")
	if (msg)
	location.href = path + '/id/' + id;
	else
	return false;
}

function loadModule(url)
{
	var loading = $("body").busyBox({
        spinner: '<img src="/images/admin/ajax-loader.gif" />'
    }); 
    
    $.ajax({
		type: "POST",
		//cache: false,
		data: "url=" + url,
    	url: "/admin/index/loadmodule/",
    	success: function(data, textStatus, XMLHttpRequest){
    	   $("#bodyText").html(data);       
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            loading.busyBox('close');
        }
	});
}

function loadPage(url)
{
	var loading = $("body").busyBox({
        spinner: '<img src="/images/admin/ajax-loader.gif" />'
    }); 
    
    $.ajax({
		type: "POST",
		//cache: false,
    	url: url,
    	success: function(html, textStatus, XMLHttpRequest){
    	   $("#bodyText").html(html);           	   
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            loading.busyBox('close');
        }
	});
}

function getCity(obj)
{
	//var country_id = $("#hotel_country option:selected").val();
        var country_id = typeof obj !== 'undefined' ? obj : document.getElementById("hotel_country").value;

	//var country_id = document.getElementById("hotel_country").value;
	$.ajax ({
    	type: "POST",
    	data: "country=" + country_id,
    	url: "/default/index/getcity/",
    	success: function(data){
            if(typeof obj !== 'undefined'){
                $("#hotel_city_booking").html(data);       
            }else{
                $("#hotel_city").html(data);       
            }                
    	}
	});
}

function getHotels(obj) {
    var country_id = typeof obj !== 'undefined' ? obj : $("#hotel_city option:selected").val();
	//var country_id = $("#hotel_city option:selected").val();
    
    $.ajax ({
    	type: "POST",
    	data: "city=" + country_id,
    	url: "/default/index/gethotel/",
    	success: function(data){
            if(typeof obj !== 'undefined'){
                $("#cmbhotel_booking").html(data);                   
            }else{
                $("#cmbhotel").html(data);       
            }
    	}
	});
}

function validate(rel)
{
	jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
		if(r==true){

			
			var url = "/admin/newsletter/delete/newsletter_id/"+rel; 
		
			$(location).attr('href',url);

		}
		else
		{
		}
	});
}

$("#template_id").change(function() {	
    $.ajax
    ({
    type: "POST",
    data: "template_id=" + $(this).val(),
    url: "/admin/template/gettemplate/",
    success: function(responseText){
    	
    	$data = responseText.split("|");
    	
    	var oFCKeditor_en = new FCKeditor('newsletter_content_en');
    	var oFCKeditor_ru = new FCKeditor('newsletter_content_ru');
     	var oEditorHTML = FCKeditorAPI.GetInstance('newsletter_content_en').SetHTML($data[0]);
     	var oEditorHTML = FCKeditorAPI.GetInstance('newsletter_content_ru').SetHTML($data[1]);
    }
    });   
});

function startUpload() {
    document.getElementById('f1_upload_process').style.visibility = 'visible';
    return true;
}

function stopUpload(success) {
    var result = '';
    if (success == 1) {
        document.getElementById('result').innerHTML =
        '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
    }
    else {
        document.getElementById('result').innerHTML =
        '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
    }
    document.getElementById('f1_upload_process').style.visibility = 'hidden';
    return true;
}

var fname = $("#firstname");
var lname = $("#lastname");
var email = $("#email");
var nickname = $("#username");
var password = $("#password");
var userlevel = document.getElementById("userlevel");
var status = document.getElementById("status");
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var msg = "";
$("#saveuser").click(function() {
    if(fname.val() == "") {
        msg = "First nName is required and cannot be blank";
        alert(msg);
        fname.focus();
        return false;
    } else if(lname.val() == "") {
        msg = "Last name is required and cannot be blank";
        alert(msg);
        lname.focus();
        return false;
    } else if(email.val() == "") {
        msg = "Email address is required and cannot be blank";
        alert(msg);
        email.focus();
        return false;
    } else if(email.val() != "" && reg.test(email.val()) == false) {
        msg = "Invalid email address";
        alert(msg);
        email.focus();
        return false;
    } else if(nickname.val() == "") {
        msg = "Nickname is required and cannot be blank";
        alert(msg);
        nickname.focus();
        return false;
    } else if(nickname.val() != "" && nickname.val().length < 5) {
        msg = "Nickname should be greater than 5 characters due to security reasons";
        alert(msg);
        nickname.focus();
        return false;
    } else if(nickname.val() != "" && nickname.val().length > 15) {
        msg = "Nickname should be less than 15 characters due to security reasons";
        alert(msg);
        nickname.focus();
        return false;
    } else if(password.val() == "") {
        msg = "Password is required and cannot be blank";
        alert(msg);
        password.focus();
        return false;
    } else if(password.val() != "" && password.val().length < 5) {
        msg = "Password should be greater than 5 characters due to security reasons";
        alert(msg);
        password.focus();
        return false;
    } else if(password.val() != "" && password.val().length > 15) {
        msg = "Password should be less than 15 characters due to security reasons";
        alert(msg);
        password.focus();
        return false;
    } else if(userlevel.value == "") {
        msg = "User level is required and cannot be blank";
        alert(msg);
        userlevel.focus();
        return false; 
    } else if(status.value == "") {
        msg = "User status is required and cannot be blank";
        alert(msg);
        status.focus();
        return false; 
    } else {        
        $.ajax ({
        	type: "POST",
        	data: ({firstname: fname.val(), lastname: lname.val(), email: email.val(), username: nickname.val(), password: password.val(), userlevel: userlevel.value, status: status.value}),
        	url: "/admin/user/doadduser/",
        	success: function(data){
        	   alert(data);
        	   loadPage("/admin/user/index/");    
        	}
        });
    }
});

function savenewsletter() {
    var template_id = document.getElementById("template_id");
    var newsletter_title = $("#newsletter_title");
    var newsletter_content_en = FCKeditorAPI.GetInstance("newsletter_content_en").EditorWindow.parent.FCK.GetHTML();
    var newsletter_content_ru = FCKeditorAPI.GetInstance("newsletter_content_ru").EditorWindow.parent.FCK.GetHTML();
    var status = document.getElementById("status");
    var msg = "";
    
    if(template_id.value == "")
    {
        msg = "Template is required and cannot be blank";
        alert(msg);
        template_id.focus();
        return false;
    } else if(newsletter_title.val() == "") {
        msg = "Newsletter title is required and cannot be blank";
        alert(msg);
        newsletter_title.focus();
        return false;
    } else if(status.value == "") {
    	msg = "Newsletter status is required and cannot be blank";
        alert(msg);
        status.focus();
        return false;
    } else {
    	$.ajax ({
        	type: "POST",
        	data: ({template_id: template_id.value, newsletter_title: newsletter_title.val(), newsletter_content_en: newsletter_content_en, newsletter_content_ru: newsletter_content_ru, status: status.value}),
        	url: "/admin/newsletter/doaddnewsletter/",
        	success: function(data){
        	   alert(data); 
        	   loadPage("/admin/newsletter/index/");      
        	}
        });
    }
}

$("#updateuser").click( function() {
    var firstname = $("#f_name");
    var lastname = $("#l_name");
    var email = $("#email");
    var userlevel = document.getElementById("userlevel");
    var status = document.getElementById("status");
    var userid = $("#userid");
    if(firstname.val() == "") {
        msg = "First name is required and cannot be blank";
        alert(msg);
        fname.focus();
        return false;
    } else if(lastname.val() == "") {
        msg = "Last name is required and cannot be blank";
        alert(msg);
        lname.focus();
        return false;
    } else if(email.val() == "") {
        msg = "Email address is required and cannot be blank";
        alert(msg);
        email.focus();
        return false;
    } else if(email.val() != "" && reg.test(email.val()) == false) {
        msg = "Invalid email address";
        alert(msg);
        email.focus();
        return false;
    } else {
        $.ajax ({
        	type: "POST",
        	data: ({userid: userid.val(), firstname: firstname.val(), lastname: lastname.val(), email: email.val(), userlevel: userlevel.value, status: status.value}),
        	url: "/admin/user/doedituser/",
        	success: function(data){
        	   alert(data);
        	   loadPage("/admin/user/index/");       
        	}
        });
    }
});

function updatenewsletter() {
    var newsletter_id = $("#newsletter_id");
    var template_id = document.getElementById("template_id");
    var newsletter_title = $("#newsletter_title");
    var newsletter_content_en = FCKeditorAPI.GetInstance("newsletter_content_en").EditorWindow.parent.FCK.GetHTML();   
    var newsletter_content_ru = FCKeditorAPI.GetInstance("newsletter_content_ru").EditorWindow.parent.FCK.GetHTML(); 
    var status = document.getElementById("status");
    if(template_id.value == "")
    {
        msg = "Template is required and cannot be blank";
        alert(msg);
        template_id.focus();
        return false;
    } else if(newsletter_title.val() == "") {
        msg = "Newsletter Title is required and cannot be blank";
        alert(msg);
        newsletter_title.focus();
        return false;
    } else if(status.value == "") {
    	msg = "Newsletter status is required and cannot be blank";
        alert(msg);
        status.focus();
        return false;
    } else {
    	$.ajax ({
        	type: "POST",
        	data: ({newsletter_id: newsletter_id.val(), template_id: template_id.value, newsletter_title: newsletter_title.val(), newsletter_content_en: newsletter_content_en, newsletter_content_ru: newsletter_content_ru}),
        	url: "/admin/newsletter/updatenewsletter/",
        	success: function(data){
        	   alert(data); 
        	   loadPage("/admin/newsletter/index/");      
        	}
        });
    }
}

function showPasswordForm()
{
    $("#edit_password").show().fadein('fast');
}

function getSelected(opt) {
    var selected = new Array();
    var index = 0;
    for (var intLoop = 0; intLoop < opt.length; intLoop++) {
        if ((opt[intLoop].selected) ||
            (opt[intLoop].checked)) {
          index = selected.length;
          selected[index] = new Object;
          selected[index].value = opt[intLoop].value;
          selected[index].index = intLoop;
        }
    }
    return selected;
}

$("#deleteuser").click(function () {
    var selector_checked = $("input[@id=selector]:checked").length; 
    var selector_val = $("input[@id=selector]:checked"); 
    var sel = getSelected(selector_val);
    var strSel = "";
    for (var item in sel)       
       strSel += sel[item].value + "--";
    $.ajax
    ({
        type: "POST",
        data: ({user_arr: strSel}),
        url: "/admin/user/deleteuser/",
        success: function(data){
            alert(data);
            loadPage("/admin/user/index/");	
        }
    }); 
});

function savetemplate() {
    var module_name = $("#module_name"); 
   	var template_title = $("#template_title");
   	var template_content_en = FCKeditorAPI.GetInstance("template_content_en").EditorWindow.parent.FCK.GetHTML();  
   	var template_content_ru = FCKeditorAPI.GetInstance("template_content_ru").EditorWindow.parent.FCK.GetHTML();  
   	//var is_default = $("input[@id=is_default]:checked");
   
   	var msg = "";
   	if(module_name.val() == "")
   	{
       msg = "Module name is required and cannot be blank";
       alert(msg);
       module_name.focus();
       return false;
   	} else if(template_title.val() == "") {
       msg = "Template Title is required and cannot be blank";
       alert(msg);
       template_title.focus();
       return false;
   	} else {
        $.ajax
        ({
            type: "POST",
            data: ({module_name: module_name.val(), template_title: template_title.val(), template_content_en: template_content_en, template_content_ru: template_content_ru}),
            url: "/admin/template/doaddtemplate/",
            success: function(responseText){
                alert(responseText);
                loadPage("/admin/template/index/");	
            }
        });
   	}
}

function updatetemplate() {
   	var template_id = $("#template_id").val();
	var module_name = $("#module_name"); 
   	var template_title = $("#template_title");
   	var template_content_en = FCKeditorAPI.GetInstance("template_content_en").EditorWindow.parent.FCK.GetHTML();  
   	var template_content_ru = FCKeditorAPI.GetInstance("template_content_ru").EditorWindow.parent.FCK.GetHTML();  
   	//var is_default = $("input[@id=is_default]:checked");
   
   	var msg = "";
   	if(module_name.val() == "")
   	{
       msg = "Module name is required and cannot be blank";
       alert(msg);
       module_name.focus();
       return false;
   	} else if(template_title.val() == "") {
       msg = "Template Title is required and cannot be blank";
       alert(msg);
       template_title.focus();
       return false;
   	} else {
        $.ajax
        ({
            type: "POST",
            data: ({template_id: template_id, module_name: module_name.val(), template_title: template_title.val(), template_content_en: template_content_en, template_content_ru: template_content_ru}),
            url: "/admin/template/doupdatetemplate/",
            success: function(responseText){
                alert(responseText);
                loadPage("/admin/template/index/");	
            }
        });
   	}
}

function deleteNewsletter(newsletter_id)
{
	var msg = confirm ("Are you sure you want to delete this newsletter?")
	if (msg) {
    	//location.href = '/admin/user/deleteuser/userid/'+userid;
    	$.ajax({
    		type: "POST",
    		data: ({n_id: newsletter_id}),
        	url: "/admin/newsletter/delete/",
        	success: function(data, textStatus, XMLHttpRequest){
        	   alert(data);
        	   loadPage("/admin/newsletter/index/");
        	}
    	});
	} else {
	   return false;
	} 
}

function deleteTemplate(template_id)
{
	var msg = confirm ("Are you sure you want to delete this template?")
	if (msg) {
    	//location.href = '/admin/user/deleteuser/userid/'+userid;
    	$.ajax({
    		type: "POST",
    		data: ({template_id: template_id}),
        	url: "/admin/template/deletetemplate/",
        	success: function(data, textStatus, XMLHttpRequest){
        	   alert(data);
        	   loadPage("/admin/template/index/");
        	}
    	});
	} else {
	   return false;
	} 
}

function popup(mylink, windowname)
{
	if (! window.focus)return true;
		var href;
	if (typeof(mylink) == 'string')
	   	href=mylink;
	else
	   	href=mylink.href;
		window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
		return false;
}

 

function savehotel() 
{
	var hotel_title = $("#hotel_title");
	var hotel_country = document.getElementById("hotel_country");
	var hotel_city = document.getElementById("hotel_city");
    var hotel_description = $("#hotel_description");
    var hotel_facility_en = FCKeditorAPI.GetInstance("hotel_facility_en").EditorWindow.parent.FCK.GetHTML();
    var hotel_facility_ru = FCKeditorAPI.GetInstance("hotel_facility_ru").EditorWindow.parent.FCK.GetHTML();
    var contact_person = $("#contact_person");
    var contact_email = $("#contact_email");
    var hotel_phone = $("#hotel_phone");
    var hotel_fax = $("#hotel_fax");
    var hotel_skype = $("#hotel_skype");
    var no_of_rooms = $("#no_rooms");
    var is_enabled = document.getElementById("is_Enabled");
    
   	
    if(hotel_title.val() == "") {
    	alert("Hotel Title is required and cannot be blank");
    	hotel_title.focus();
    	return false;
    } else if(hotel_country.value == "") {
    	alert("Country is required and cannot be blank")
    	return false;
    } else if(hotel_city.value == "") {
    	alert("City is required and cannot be blank");
    	return false;
    } else if(contact_email.val() != "" && reg.test(contact_email.val()) == false) {
        alert("Invalid Email address");
        contact_email.focus();
        return false;
    } else if(hotel_phone.val() == "") {
    	alert("Hotel Contact Number is required and cannot be balnk");
    	hotel_phone.focus();
    	return false;
    } else {
    	$.ajax
        ({
            type: "POST",
            data: ({hotel_title: hotel_title.val(), hotel_country: hotel_country.value, hotel_city: hotel_city.value, hotel_description: hotel_description.val(), hotel_facility_en: hotel_facility_en, hotel_facility_ru: hotel_facility_ru, contact_person: contact_person.val(), contact_email: contact_email.val(), hotel_phone: hotel_phone.val(), hotel_fax: hotel_fax.val(), hotel_skype: hotel_skype.val(), no_of_rooms: no_of_rooms.val(), is_enabled: is_enabled.value}),
            url: "/admin/hotel/doaddhotel/",
            success: function(responseText){                
                loadPage("/admin/hotel/index/");	
            }
        });
    }
}

function getBackPage(url) {
	var loading = $("body").busyBox({
        spinner: '<img src="/images/admin/ajax-loader.gif" />'
    }); 
    
    loadPage(url);
    
    loading.busyBox('close');  
}

function deleteHotel(hotel_id)
{
	var msg = confirm ("Are you sure you want to delete this record?")
	if (msg) {
    	//location.href = '/admin/user/deleteuser/userid/'+userid;
    	$.ajax({
    		type: "POST",
    		data: ({h_id: hotel_id}),
        	url: "/admin/hotel/delete/",
        	success: function(data, textStatus, XMLHttpRequest){
        	   alert(data);
        	   loadPage("/admin/hotel/index/");
        	}
    	});
	} else {
	   return false;
	} 
}

function addAmenities(hotel_id)
{
	var loading = $("body").busyBox({
        spinner: '<img src="/images/admin/ajax-loader.gif" />'
    }); 
    
    $.ajax({
		type: "POST",
		//cache: false,
		data: ({h_id: hotel_id}),
    	url: "/admin/hotel/addamenity/",
    	success: function(data, textStatus, XMLHttpRequest){
			$("#formamenity").jqpopup_open("formamenity",true);				
		   	$("#table_content").html(data);	         	   
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            loading.busyBox('close');
        }
	});
}

$("#btnAddAmenity").click(function() 
{
	var amenity_checked = $("input[@id=amenity]:checked");
	var hotel_id = $("#hotel_id").val();
	var amenity_val = [];
    amenity_checked.each(function(index){
        amenity_val[index] = amenity_checked[index].value;        
    });
    
    if(amenity_val == "")
    {
    	alert("Please select at least one amenity");
    } else {
    	$.ajax({
		type: "POST",
		//cache: false,
		data: ({amenity_val: amenity_val, hotel_id: hotel_id}),
    	url: "/admin/hotel/doaddamenity/",
    	success: function(data, textStatus, XMLHttpRequest){
    	   alert(data);
    	   $("#formamenity").jqpopup_close("formamenity",true);           	   
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            loading.busyBox('close');
        }
	});
    }
});

function addRates(hotel_id)
{
	var loading = $("body").busyBox({
        spinner: '<img src="/images/admin/ajax-loader.gif" />'
    }); 
    
    $.ajax({
		type: "POST",
		//cache: false,
		data: ({h_id: hotel_id}),
    	url: "/admin/rates/index/",
    	success: function(data, textStatus, XMLHttpRequest){
			$("#formamenity").jqpopup_open("formamenity",true);				
		   	$("#table_content").html(data);	         	   
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            loading.busyBox('close');
        }
	});
}
function saverates(){
 
	var hotel_id = document.getElementById("hotel_id");
	var rate_category = $("#rate_category");
	var rate_basis = $("#rate_basis");
	var fromdate = $("#fromdate");
	var todate = $("#todate");
	var rate_additionalinfo = FCKeditorAPI.GetInstance("rate_additionalinfo").EditorWindow.parent.FCK.GetHTML();
	
	if(hotel_id.value == "")
	{
		alert("Hotel is required and cannot be blank");
		hotel_id.focus();
		return false;
	} else if(rate_category.val() == "") {
		alert("Rate Category is required and cannot be blank");
		rate_category.focus();
		return false;
	} else if(rate_basis.val() == "") {
		alert("Rate Basis is required and cannot be blank");
		rate_basis.focus();
		return false;
	}else if(fromdate.val() == "") {
		alert("Rate Single is required and cannot be blank");
		fromdate.focus();
		return false;
	} else if(todate.val() == "") {
		alert("Rate Double is required and cannot be blank");
		todate.focus();
		return false;
	} else {
		$.ajax({
			type: "POST",
			//cache: false,
			data: ({hotel_id: hotel_id.value, rate_category: rate_category.val(), rate_basis: rate_basis.val(), fromdate: fromdate.val(), todate: todate.val(), rate_additionalinfo: rate_additionalinfo}),
	    	url: "/admin/rates/doaddrates/",
	    	success: function(data, textStatus, XMLHttpRequest){
				alert(data);
				loadPage("/admin/rates/index/hotel_id/"+hotel_id.value);
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	            loading.busyBox('close');
	        }
		});
	}
 
}
function updaterates() {
	var rate_id = $("#rate_id");
	var hotel_id = document.getElementById("hotel_id");
	var rate_category = $("#rate_category");
	var rate_basis = $("#rate_basis");
	var fromdate = $("#fromdate");
	var todate = $("#todate");
	var rate_additionalinfo = FCKeditorAPI.GetInstance("rate_additionalinfo").EditorWindow.parent.FCK.GetHTML();
	
	if(hotel_id.value == "")
	{
		alert("Hotel is required and cannot be blank");
		hotel_id.focus();
		return false;
	} else if(rate_category.val() == "") {
		alert("Rate Category is required and cannot be blank");
		rate_category.focus();
		return false;
	} else if(rate_basis.val() == "") {
		alert("Rate Basis is required and cannot be blank");
		rate_basis.focus();
		return false;
	} else if(fromdate.val() == "") {
		alert("Rate Single is required and cannot be blank");
		fromdate.focus();
		return false;
	} else if(todate.val() == "") {
		alert("Rate Double is required and cannot be blank");
		todate.focus();
		return false;
	} else {
		$.ajax({
			type: "POST",
			//cache: false,
			data: ({rate_id: rate_id.val(), hotel_id: hotel_id.value, rate_category: rate_category.val(), rate_basis: rate_basis.val(), fromdate: fromdate.val(), todate: todate.val(), rate_additionalinfo: rate_additionalinfo}),
	    	url: "/admin/rates/updaterates/",
	    	success: function(data, textStatus, XMLHttpRequest){
				alert(data);
                                loadPage("/admin/rates/index/hotel_id/"+hotel_id.value);
	    	},
	    	complete: function complete(XMLHttpRequest, textStatus){
	          //  loading.busyBox('close');
	        }
		});
	}
}

function deleteRates(rate_id,hotel_id)
{
	var msg = confirm ("Are you sure you want to delete this record?")
	if (msg) {
    	//location.href = '/admin/user/deleteuser/userid/'+userid;
    	$.ajax({
    		type: "POST",
    		data: ({rate_id: rate_id}),
        	url: "/admin/rates/delete/",
        	success: function(data, textStatus, XMLHttpRequest){
        	   	alert(data);
        	   	// $("#grid_rate").load();
        	  	//$("#grid_rate").append();
        	  	//setTimeout(redirect("/admin/index/"), 1000);        	  	
        	  	  loadPage("/admin/rates/index/hotel_id/"+hotel_id);
        	}
    	});
	} else {
	   return false;
	} 
}

function redirect(url)
{
	document.location.href = url;
}

function showEditPassword()
{
	var userid = $("#userid").val();
	var loading = $("body").busyBox({
        spinner: '<img src="/images/admin/ajax-loader.gif" />'
    });
    
	$.ajax({
		type: "POST",
		data: ({userid: userid}),
		url: "/admin/user/editpass/",
    	success: function(data, textStatus, XMLHttpRequest){
    	   	$("#editpassword").jqpopup_open("editpassword",true);
    	   	$("#frmeditpassword").html(data);	 
    	},
    	complete: function complete(XMLHttpRequest, textStatus){
            loading.busyBox('close');           
        }
	});
}

function changePassword(userid)
{
    var userid = userid;
    var curr_pwd = $("#txtPasswd1");
    var new_pwd = $("#txtPasswd2");
    
    if(curr_pwd.val() == "")
    {
        alert("Please enter your current password");
        curr_pwd.focus();
        return false;
    } else if(new_pwd.val() == "") {
        alert("Please enter your new password");
        new_pwd.focus();
        return false;
    } else {    
        $.ajax
        ({
            type: "POST",
            data: ({userid: userid, curr_pwd: curr_pwd.val(), new_pwd: new_pwd.val()}),
            url: "/admin/user/doeditpwd/",
            success: function(responseText){
                alert(responseText);	
                $("#editpassword").jqpopup_close("editpassword",true);
            }
        });
    }        
}

function savetour() {
	var tour_title = $("#tour_title");
    var tour_description_en = FCKeditorAPI.GetInstance("tour_description_en").EditorWindow.parent.FCK.GetHTML();   
    var tour_description_ru = FCKeditorAPI.GetInstance("tour_description_ru").EditorWindow.parent.FCK.GetHTML();   
    var no_days = $("#no_days");
    var no_nights = $("#no_nights");
    var tour_includes_en = FCKeditorAPI.GetInstance("tour_includes_en").EditorWindow.parent.FCK.GetHTML(); 
    var tour_includes_ru = FCKeditorAPI.GetInstance("tour_includes_ru").EditorWindow.parent.FCK.GetHTML(); 
    var tour_excludes_en = FCKeditorAPI.GetInstance("tour_excludes_en").EditorWindow.parent.FCK.GetHTML();
    var tour_excludes_ru = FCKeditorAPI.GetInstance("tour_excludes_ru").EditorWindow.parent.FCK.GetHTML();
    var status = document.getElementById("status");
    
    var msg = "";
    
    if(tour_title.val() == "")
    {
        alert("Tour title is required and cannot be blank");
        tour_title.focus();
        return false;
    } else if(no_days.val() == "") {
        msg = "No. of days is required and cannot be blank";
        alert(msg);
        no_days.focus();
        return false;
    } else if(no_nights.val() == "") {
        msg = "No. of nights is required and cannot be blank";
        alert(msg);
        no_nights.focus();
        return false;
    } else {
        $.ajax ({
        	type: "POST",
        	data: ({tour_title: tour_title.val(), tour_description_en: tour_description_en, tour_description_ru: tour_description_ru, no_days: no_days.val(), no_nights: no_nights.val(), tour_includes_en: tour_includes_en, tour_includes_ru: tour_includes_ru, tour_excludes_en: tour_excludes_en, tour_excludes_ru: tour_excludes_ru, status: status.value}),
        	url: "/admin/tour/doaddtour/",
        	success: function(data){
        	   alert(data); 
        	   loadPage("/admin/tour/index/");      
        	}
        });
    }
}

/*$("#savetour").click( function() {
	var tour_title = $("#tour_title");
    var tour_description_en = FCKeditorAPI.GetInstance("tour_description_en").EditorWindow.parent.FCK.GetHTML();   
    var tour_description_ru = FCKeditorAPI.GetInstance("tour_description_ru").EditorWindow.parent.FCK.GetHTML();   
    var no_days = $("#no_days");
    var no_nights = $("#no_nights");
    var tour_includes_en = FCKeditorAPI.GetInstance("tour_includes_en").EditorWindow.parent.FCK.GetHTML(); 
    var tour_includes_ru = FCKeditorAPI.GetInstance("tour_includes_ru").EditorWindow.parent.FCK.GetHTML(); 
    var tour_excludes_en = FCKeditorAPI.GetInstance("tour_excludes_en").EditorWindow.parent.FCK.GetHTML();
    var tour_excludes_ru = FCKeditorAPI.GetInstance("tour_excludes_ru").EditorWindow.parent.FCK.GetHTML();
    var status = document.getElementById("status");
    
    var msg = "";
    
    if(tour_title.val() == "")
    {
        alert("Tour title is required and cannot be blank");
        tour_title.focus();
        return false;
    } else if(no_days.val() == "") {
        msg = "No. of days is required and cannot be blank";
        alert(msg);
        no_days.focus();
        return false;
    } else if(no_nights.val() == "") {
        msg = "No. of nights is required and cannot be blank";
        alert(msg);
        no_nights.focus();
        return false;
    } else {
        $.ajax ({
        	type: "POST",
        	data: ({tour_title: tour_title.val(), tour_description_en: tour_description_en, tour_description_ru: tour_description_ru, no_days: no_days.val(), no_nights: no_nights.val(), tour_includes_en: tour_includes_en, tour_includes_ru: tour_includes_ru, tour_excludes_en: tour_excludes_en, tour_excludes_ru: tour_excludes_ru, status: status.value}),
        	url: "/admin/tour/doaddtour/",
        	success: function(data){
        	   alert(data); 
        	   loadPage("/admin/tour/index/");      
        	}
        });
    }
});*/

function updatetour() {
    var tour_id = $("#tour_id").val();
	var tour_title = $("#tour_title");
    var tour_description_en = FCKeditorAPI.GetInstance("tour_description_en").EditorWindow.parent.FCK.GetHTML();   
    var tour_description_ru = FCKeditorAPI.GetInstance("tour_description_ru").EditorWindow.parent.FCK.GetHTML();   
    var no_days = $("#no_days");
    var no_nights = $("#no_nights");
    var tour_includes_en = FCKeditorAPI.GetInstance("tour_includes_en").EditorWindow.parent.FCK.GetHTML(); 
    var tour_includes_ru = FCKeditorAPI.GetInstance("tour_includes_ru").EditorWindow.parent.FCK.GetHTML(); 
    var tour_excludes_en = FCKeditorAPI.GetInstance("tour_excludes_en").EditorWindow.parent.FCK.GetHTML();
    var tour_excludes_ru = FCKeditorAPI.GetInstance("tour_excludes_ru").EditorWindow.parent.FCK.GetHTML();
    var status = document.getElementById("status");  
    if(tour_title.value == "")
    {
        msg = "Tour title is required and cannot be blank";
        alert(msg);
        tour_title.focus();
        return false;
    } else if(no_days.val() == "") {
        msg = "No. of days is required and cannot be blank";
        alert(msg);
        no_days.focus();
        return false;
    } else if(no_nights.val() == "") {
        msg = "No. of nights is required and cannot be blank";
        alert(msg);
        no_nights.focus();
        return false;
    } else {
        $.ajax ({
        	type: "POST",
        	data: ({tour_id: tour_id, tour_title: tour_title.val(), tour_description_en: tour_description_en, tour_description_ru: tour_description_ru, no_days: no_days.val(), no_nights: no_nights.val(), tour_includes_en: tour_includes_en, tour_includes_ru: tour_includes_ru, tour_excludes_en: tour_excludes_en, tour_excludes_ru: tour_excludes_ru, status: status.value}),
        	url: "/admin/tour/updatetour/",
        	success: function(data){
        	   alert(data); 
        	   loadPage("/admin/tour/index/");      
        	}
        });
    }
}

function deleteTour(tour_id)
{
	var msg = confirm ("Are you sure you want to delete this tour?")
	if (msg) {
    	//location.href = '/admin/user/deleteuser/userid/'+userid;
    	$.ajax({
    		type: "POST",
    		data: ({tour_id: tour_id}),
        	url: "/admin/tour/delete/",
        	success: function(data, textStatus, XMLHttpRequest){
        	   alert(data);
        	   loadPage("/admin/tour/index/");
        	}
    	});
	} else {
	   return false;
	} 
}

function saveaboutcountry() {
	var category = $("#category");
	var title = $("#title");
	var page_description_en = FCKeditorAPI.GetInstance("page_description_en").EditorWindow.parent.FCK.GetHTML();
	var page_description_ru = FCKeditorAPI.GetInstance("page_description_ru").EditorWindow.parent.FCK.GetHTML();
	var status = document.getElementById("status");  

        var loading = $("body").busyBox({
            spinner: '<img src="/images/admin/ajax-loader.gif" />'
        });
	if(category.val() == "")
	{
		alert("Category is required and cannot be blank");
		category.focus();
		return false;	
	} else if(title.val() == "") {
		alert("Page title is required and cannot be blank");
		title.focus();
		return false;	
	} else if(status.value == "") {
		alert("Status is required and cannot be blank");
		status.focus();
		return false;	
	} else {
        $.ajax ({
        	type: "POST",
        	data: ({category: category.val(), page_title: title.val(), page_description_en: page_description_en, page_description_ru: page_description_ru, status: status.value}),
        	url: "/admin/aboutcountry/doaddaboutcountry/",
        	success: function(data){
        		alert(data);
        	   	loadPage("/admin/aboutcountry/index/");      
        	},
                complete: function complete(XMLHttpRequest, textStatus){
                    loading.busyBox('close');
                }
        });
    }	
}

function updateaboutcountry() {
	var page_id = document.getElementById("page_id").value;
	var category = $("#category");
	var title = $("#title");
	var page_description_en = FCKeditorAPI.GetInstance("page_description_en").EditorWindow.parent.FCK.GetHTML();
	var page_description_ru = FCKeditorAPI.GetInstance("page_description_ru").EditorWindow.parent.FCK.GetHTML();
	var status = document.getElementById("status");  
	
	if(category.val() == "")
	{
		alert("Category is required and cannot be blank");
		category.focus();
		return false;	
	} else if(title.val() == "") {
		alert("Page title is required and cannot be blank");
		title.focus();
		return false;	
	} else if(status.value == "") {
		alert("Status is required and cannot be blank");
		status.focus();
		return false;	
	} else {
        $.ajax ({
        	type: "POST",
        	data: ({page_id: page_id, category: category.val(), page_title: title.val(), page_description_en: page_description_en, page_description_ru: page_description_ru, status: status.value}),
        	url: "/admin/aboutcountry/doupdateaboutcountry/",
        	success: function(data){
        	   alert(data); 
        	   loadPage("/admin/aboutcountry/index/");      
        	}
        });
    }	
}

function updatehotel() 
{
	var hotel_title = $("#hotel_title");
	var hotel_country = document.getElementById("hotel_country");
	var hotel_city = document.getElementById("hotel_city");
    var hotel_description = $("#hotel_description");
    var hotel_facility_en = FCKeditorAPI.GetInstance("hotel_facility_en").EditorWindow.parent.FCK.GetHTML();
    var hotel_facility_ru = FCKeditorAPI.GetInstance("hotel_facility_ru").EditorWindow.parent.FCK.GetHTML();
    var contact_person = $("#contact_person");
    var contact_email = $("#contact_email");
    var hotel_phone = $("#hotel_phone");
    var hotel_fax = $("#hotel_fax");
    var hotel_skype = $("#hotel_skype");
    var no_of_rooms = $("#no_rooms");
    
    var remarks = $("#remarks");
    var is_enabled = document.getElementById("is_Enabled");
    var hotel_id = $("#hotel_id").val();
   	
    if(hotel_title.val() == "") {
    	alert("Hotel Title is required and cannot be blank");
    	hotel_title.focus();
    	return false;
    } else if(hotel_country.value == "") {
    	alert("Country is required and cannot be blank")
    	return false;
    } else if(hotel_city.value == "") {
    	alert("City is required and cannot be blank");
    	return false;
    } else if(contact_email.val() == "") {
    	alert("Contact Email is required and cannot be blank");
    	contact_email.focus();
    	return false;	
    } else if(contact_email.val() != "" && reg.test(contact_email.val()) == false) {
        alert("Invalid Email address");
        contact_email.focus();
        return false;
    } else if(hotel_phone.val() == "") {
    	alert("Hotel Contact Number is required and cannot be balnk");
    	hotel_phone.focus();
    	return false;
    } else if(no_of_rooms.val() == "") {
    	alert("No. of rooms are required and cannot be blank");
    	no_of_rooms.focus();
    	return false;
    } else {
    	$.ajax
        ({
            type: "POST",
            data: ({hotel_id: hotel_id, hotel_title: hotel_title.val(), hotel_country: hotel_country.value, hotel_city: hotel_city.value, hotel_description: hotel_description.val(), hotel_facility_en: hotel_facility_en, hotel_facility_ru: hotel_facility_ru, contact_person: contact_person.val(), contact_email: contact_email.val(), hotel_phone: hotel_phone.val(), hotel_fax: hotel_fax.val(), hotel_skype: hotel_skype.val(), no_of_rooms: no_of_rooms.val(), is_enabled: is_enabled.value}),
            url: "/admin/hotel/doupdatehotel/",
            success: function(responseText){
                alert(responseText);
                loadPage("/admin/hotel/index/");	
            }
        });
    }
}

$("#saveroomcategory").click(function() {
	var room_cat = $("#room_cat");
	var roomtype_checked = $("input[@id=room_type]:checked");
	var roomtype_val = [];
    roomtype_checked.each(function(index){
        roomtype_val[index] = roomtype_checked[index].value;        
    });
	var status = document.getElementById("status");
	
	if(room_cat.val() == "")
	{
		alert("Room category is required and cannot be blank");
		room_cat.focus();
		return false;
	} else if(roomtype_val == "") {
    	alert("Please select at least one type");
    	return false;
    } else if(status.value == "") {
    	alert("Status is required and cannot be blank");
    	return false;
    } else {
    	$.ajax
        ({
            type: "POST",
            data: ({room_cat: room_cat.val(), roomtype_val: roomtype_val, status: status.value}),
            url: "/admin/roomcats/doaddroomcat/",
            success: function(responseText){
                alert(responseText);
                loadPage("/admin/roomcats/index/");	
            }
        });
    }
});

$("#updateroomcategory").click(function() {
	var room_cat = $("#room_cat");
	var roomtype_checked = $("input[@id=room_type]:checked");
	var roomtype_val = [];
    roomtype_checked.each(function(index){
        roomtype_val[index] = roomtype_checked[index].value;        
    });
	var status = document.getElementById("status");
	var roomcat_id = $("#roomcatid").val();
	
	if(room_cat.val() == "")
	{
		alert("Room category is required and cannot be blank");
		room_cat.focus();
		return false;
	} else if(roomtype_val == "") {
    	alert("Please select at least one type");
    	return false;
    } else {
    	$.ajax
        ({
            type: "POST",
            data: ({roomcat_id: roomcat_id, room_cat: room_cat.val(), roomtype_val: roomtype_val, status: status.value}),
            url: "/admin/roomcats/updateroomcat/",
            success: function(responseText){
                alert(responseText);
                loadPage("/admin/roomcats/index/");	
            }
        });
    }
});

function getRoomTypes() {
	var roomcat_id = document.getElementById('cmbRoomCat');
	$.ajax
    ({
        type: "POST",
        data: ({roomcat_id: roomcat_id.value}),
        url: "/default/hotel/getroomtype/",
        success: function(data){
            $("#cmbRoomType").html(data);
        }
    });
}

function getCityByCountry() {
	var country_id = document.getElementById("cmbCountry").value;
	$.ajax ({
    	type: "POST",
    	data: "country=" + country_id,
    	url: "/default/index/getcity/",
    	success: function(data){
    	   $("#cmbCity").html(data);       
    	}
	});
}

function getHotelsByCity() {	
	var city_id = document.getElementById("cmbCity").value;
    
    $.ajax ({
    	type: "POST",
    	data: "city=" + city_id,
    	url: "/default/index/gethotel/",
    	success: function(data){
    	   $("#cmbHotel").html(data);       
    	}
	});
}



/*$("#savetranslate").click(function () {
	var section = document.getElementById("section");
	var english_text = document.getElementById("english_text");
	var russian_text = document.getElementById("russian_text");
	
	if(section.selectedIndex == 0) {
		alert("Section is required and cannot be blank");
		section.focus();
		return false;
	} else if(english_text.value == "") {
		alert("English text is required and cannot be blank");
		english_text.focus();
		return false;
	} else if(russian_text.value == "") {
		alert("Russian text is required and cannot be blank");
		russian_text.focus();
		return false;
	} else {
		$.ajax ({
			type: "POST",
	    	data: ({section: section.value, english_text: english_text.value, russian_text: russian_text.value}),
	    	url: "/admin/translate/doaddtranslate/",
	    	success: function(data){
	    	   alert(data);
	    	   loadPage("/admin/translate/index/");	
	    	}
		});
	}
});*/


function updatelanguage() {
	var content = document.getElementById("contents");
	var id = document.getElementById("id"); 
	var lang = document.getElementById("lang"); 
	var section = document.getElementById("section").value; 
	
	/*if(content.value == "") {
		alert("Content is required and cannot be blank");
		content.focus();
		return false;
	} else {
		$.ajax({
			type: "POST",
			data: ({content: content.value, id: id.value, lang: lang.value}),
			url: "/admin/translate/updatetranslate/",
	    	success: function(data){
	    	   alert(data);
	    	   loadPage("/admin/translate/manage/section/"+section);	
	    	}
		});
	}*/
	$.ajax({
			type: "POST",
			data: ({content: content.value, id: id.value, lang: lang.value}),
			url: "/admin/translate/updatetranslate/",
	    	success: function(data){
	    	   alert(data);
	    	   loadPage("/admin/translate/manage/section/"+section);	
	    	}
		});
}

function deletePageRec(page_id)
{
	var msg = confirm ("Are you sure you want to delete this record?")
	if (msg) {
    	//location.href = '/admin/user/deleteuser/userid/'+userid;
    	$.ajax({
    		type: "POST",
    		data: ({page_id: page_id}),
        	url: "/admin/aboutcountry/delete/",
        	success: function(data, textStatus, XMLHttpRequest){
        	   alert(data);
        	   loadPage("/admin/aboutcountry/index/");
        	}
    	});
	} else {
	   return false;
	} 
}

function sendNewsletterEN(newsletter_id)
{
	var email_checked_en = $("input[@id=subs_users_en]:checked");
	var email_val_en = [];
    email_checked_en.each(function(index){
        email_val_en[index] = email_checked_en[index].value;        
    });
	
    $.ajax({
		type: "POST",
		data: ({lang: 'en', email: email_val_en, newsletter_id: newsletter_id}),
    	url: "/admin/newsletter/sendnewsletter/",
    	success: function(data, textStatus, XMLHttpRequest){
    	   alert(data);
    	   loadPage("/admin/newsletter/index/");
    	}
	});
}

function sendNewsletterRU(newsletter_id)
{
	var email_checked_ru = $("input[@id=subs_users_ru]:checked");
	var email_val_ru = [];
    email_checked_ru.each(function(index){
        email_val_ru[index] = email_checked_ru[index].value;        
    });
	
    $.ajax({
		type: "POST",
		data: ({lang: 'ru', email: email_val_ru, newsletter_id: newsletter_id}),
    	url: "/admin/newsletter/sendnewsletter/",
    	success: function(data, textStatus, XMLHttpRequest){
    	   alert(data);
    	   loadPage("/admin/newsletter/index/");
    	}
	});
}